<script lang="ts" setup>
import { ElCheckbox } from 'element-plus'
import useLogin from "../hooks/useLogin"
const {  
    registerForm,
    registerFormRef,
    registerRules,
    agreed,
    countdown,
    countryCode,
    sendVerifyCode,
    handleRegister,
    handleLogin,} = useLogin() 



</script>

<template>
   <el-card class="Page" shadow="hover">
    <el-form 
          class="form"
          :model="registerForm" 
          ref="registerFormRef" 
          :rules="registerRules"
        >
         <el-form-item class="title">
              <h1>验证登录</h1>
            </el-form-item>
          <!-- 手机号输入 -->
          <el-form-item prop="phone">
            <div class="phone-input-wrapper">

              <el-select 
                v-model = "countryCode"
                class="country-select"
                placeholder="中国 +86"
              >
                <el-option label="中国 +86" value="+86" />
              </el-select>

              <el-input
                v-model="registerForm.phone"
                placeholder="请输入手机号码"
                class="phone-input"
                size="large"
              />
            </div>
          </el-form-item>

          <!-- 验证码输入 -->
          <el-form-item prop="verifyCode">
            <div class="verify-code-wrapper">
              <el-input
                v-model="registerForm.verifyCode"
                placeholder="输入验证码"
                size="large"
                @keyup.enter="sendVerifyCode"

              />
              <el-button 
                type="success"
                class="send-code-btn"
                :disabled="countdown > 0"
                @click="sendVerifyCode"

              >
                {{ countdown > 0 ? `${countdown}s` : '发送验证码' }}
              </el-button>
            </div>
          </el-form-item>

          <!-- 注册/登录按钮 -->
          <el-form-item class="button">
              <el-button size="large" style="width: 100%;" @click="handleLogin">登录/注册</el-button>

          </el-form-item>

         <!-- 协议声明 -->
            <div class="protocol">
              <el-checkbox size="large" v-model="agreed" />
              <span>已阅读并同意</span>
              <el-link type="primary" :underline="false">《用户协议》</el-link>
              <el-link type="primary" :underline="false">《隐私政策》</el-link>
            </div>
        </el-form>
  </el-card>
</template>

<style lang="scss" scoped>
.Page{ 
          position: absolute;
          height: 65%;
          width: 76%;
          background-color: #F7F2EB;
          left: 50%;
          top: 50%;
          transform: translate(-50%,-50%);
          border-radius:20px;
          border: 1px solid #BBB;
          .form{
            flex-direction: column;
            justify-content: center;
            user-select: none;
            margin: 0 2.5rem;

            :deep(.el-form-item__content){
              border-radius: 20px;
            }

            .title{
              margin-top: 0.65rem;
              width: 100%;
              text-align: center;
              h1 {
                margin: 0; /* 新增 */
                padding: 0; /* 新增 */
                width: 100%; /* 新增 */
                color: #5A3E2F;
                letter-spacing: 2px;
              }
            }

            .input{
              width: 100%;
            // 输入框全局样式
            :deep(.el-input) {
              // 修改 placeholder
              margin-top:0.2rem ;
              border-radius: 10px;
              .el-input__inner::placeholder {
                color: #A09387;
                opacity: 0.8;
                font-size: 16px;
              }   

              
              // 修改图标
              .el-input__prefix {
                .el-icon {
                  color: #5A3E2F;
                  font-size: 1rem;
                  margin-right: 0.5rem;
                }
              }
              
              // 输入框本身样式
              .el-input__inner {
                background-color: rgba(247, 242, 235, 0.7);
                color: #5A3E2F;
                padding-left: 1.5rem;
                
                &:focus {
                  border-color: #5A3E2F;
                  box-shadow: 0 0 0 2px rgba(90, 62, 47, 0.2);
                }
              }
              
              // 密码可见性切换图标
              .el-input__suffix {
                .el-icon {
                  color: #5A3E2F;
                  font-size: 1rem;
                  cursor: pointer;
                }
              }
            }
          }
          
          .button {
            :deep(.el-button) {
              margin-top: 1rem;
              background-color: #5A3E2F;
              color: #F7F2EB;
              font-weight: bold;
              border: none;
              height: 2rem;
              font-size: 1rem;
              border-radius: 12px;
              letter-spacing: 1px;
              transition: all 0.3s;

              &:hover {
                background-color: #7A5E4F;
                transform: translateY(-2px);
                box-shadow: 0 4px 8px rgba(90, 62, 47, 0.25);
              }

              &:active {
                transform: translateY(1px);
              }
            }
          }
        }
      }

//同意协议
.protocol {
    margin-top: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #606266;
    font-size: 0.8rem;

    .el-checkbox {
      margin-right: 0.3rem;
    }

    .el-link {
      margin: 0 0.2rem;
    }
  }

  .phone-input-wrapper {
    display: flex;
    
    
    .country-select {
      width: 100px;
      align-self:center;
      background-color:#fffaf3 ;
      flex-shrink: 0;
    }
    
    .phone-input {
      flex: 1;
    }
  }
  
  .verify-code-wrapper {
    display: flex;
    gap: 8px;
    
    .verify-input {
      flex: 1;
    }
    
    .send-code-btn {
      width: 100px;
      flex-shrink: 0;
      align-self:center;
    }
  }

</style>